home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / compre1a / myagent.frm < prev    next >
Text File  |  1999-09-07  |  18KB  |  387 lines

  1. VERSION 5.00
  2. Object = "{F5BE8BC2-7DE6-11D0-91FE-00C04FD701A5}#2.0#0"; "AGENTCTL.DLL"
  3. Begin VB.Form frmMain 
  4.    Caption         =   "Accepting input"
  5.    ClientHeight    =   1695
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   4680
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   1695
  11.    ScaleWidth      =   4680
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin VB.CommandButton cmdGo 
  14.       Caption         =   "Go"
  15.       Enabled         =   0   'False
  16.       Height          =   615
  17.       Left            =   1500
  18.       TabIndex        =   0
  19.       Top             =   300
  20.       Width           =   1455
  21.    End
  22.    Begin VB.Label Label1 
  23.       Height          =   255
  24.       Left            =   660
  25.       TabIndex        =   1
  26.       Top             =   1080
  27.       Width           =   3075
  28.    End
  29.    Begin AgentObjectsCtl.Agent Agent 
  30.       Left            =   360
  31.       Top             =   300
  32.       _cx             =   847
  33.       _cy             =   847
  34.    End
  35. End
  36. Attribute VB_Name = "frmMain"
  37. Attribute VB_GlobalNameSpace = False
  38. Attribute VB_Creatable = False
  39. Attribute VB_PredeclaredId = True
  40. Attribute VB_Exposed = False
  41. Option Explicit 'This statement prevents the creation
  42.                 'of Varient variables when the variables
  43.                 'are referenced but not created before
  44.                 'e.g. For n = 1 to 10, if n was never Dim-ed
  45.  
  46. Dim IntroComplete As Boolean    'When the intro is complete
  47.                                 'this is set to true
  48.                                 'to activate some options
  49.                                 '(well 1 option actually)
  50. Dim LoadRequest(4)
  51.     'These are the LoadRequests, when one is set to a
  52. 'R  'Character command, when the command is completed the
  53. 'E  'Agent control runs extra lines of code, according to
  54. 'A  'which request was used, such as an UnLoad function.
  55. 'D  'This is needed because Agent works with Ques, so when
  56.     'you give Agent a command, that command is put into a
  57. 'T  'que, and your program carries on to the next command
  58. 'H  'in your program, thus freeing up your program to do
  59. 'I  'other things, though it also means if you give an
  60. 'S  'agent a command followed by an UnLoad Me statement,
  61. '!  'the Agent command will be qued, the program carries
  62. '!  'on, and unloads the form, and the Agent control,
  63.     'stopping everything!!
  64.     'It is a rather strange way of programming,
  65.     'but it works, and this is how Microsoft
  66.     'make their scripts too :)
  67.     'This is where many programmers go wrong, and swear at
  68.     'their computers for a few hours!
  69.     '(before kicking it out of a window)
  70.     
  71. Dim Genie As IAgentCtlCharacter
  72. Dim Merlin As IAgentCtlCharacter
  73.     'To be used in Set commands
  74.     
  75. Dim Request As IAgentCtlRequest
  76.     'To set to an agent request, so another agent can wait
  77.     'for that request in another Agent's que to complete
  78.     'before continuing the commands in it's own que,
  79.     'well, try going through this later and remove all the
  80.     ''Set Request =' bits, see what happens when you run
  81.     'it ;-)
  82.  
  83. Private Sub LoadGenie()
  84.     Set LoadRequest(0) = Agent.Characters.Load("Genie", "Genie.acs")
  85.         'This command, Sets LoadRequest(0) as the
  86.         'Agent Load command, which is run, so when the
  87.         'Agent control finishes loading the Genie.acs file
  88.         'it will run through the Agent_RequestComplete
  89.         'Subroutine (see below) and find the finished
  90.         'request equal to LeadRequest(0), and so run the
  91.         'commands in this part of code.  Using this method,
  92.         'you can set commands to only run when an Agent has
  93.         'completed an operation, such as i have used one to
  94.         'only Unload the form when Merlin has finished
  95.         'hiding, this is how you get around the Ques problem
  96.         '(strange huh?!)
  97.     
  98.     Label1.Caption = "Loading Genie character."
  99. End Sub
  100.  
  101. Private Sub LoadMerlin()
  102.     Set LoadRequest(1) = Agent.Characters.Load("Merlin", "Merlin.acs")
  103.         'Again, running code after the character is loaded
  104.         'the "Merlin" part is the Key of the agent, or its
  105.         'loaded name, how you can reference to it once it
  106.         'is loaded, and the Merlin.acs part is the path to,
  107.         'and name of the file, if the path is omitted
  108.         '(left out), the default path is used, which is
  109.         'the MS Agent characters directory, in this case
  110.         'C:\WINDOWS\MSAGENT\CHARS\
  111.         
  112.     Label1.Caption = "Loading Merlin character."
  113. End Sub
  114.  
  115. Private Sub AddMerlinCommands()
  116.     'Add voice commands to Merlin
  117.     Merlin.Commands.Add "ChPoofs", "You want some Cheesy Poofs?", "You want some Cheesy Poofs?", True, True
  118.                         'Ref Name , Caption in the popup menu etc, What it listens for         , Whether it is enabled, whether it is visible in the popupmenu and commands window
  119.     Merlin.Commands.Add "Internet", "Internet?", "Internet?", True, True
  120.     Merlin.Commands.Add "OffChar", "Can I use Office characters with Agent?", "Can I use Office characters with Agent?", True, True
  121.     Merlin.Commands.Add "Goodbye", "Goodbye", "Goodbye", True, True
  122.     Merlin.Commands.Caption = "Merlin"
  123. End Sub
  124.  
  125. Private Sub Agent_Click(ByVal CharacterID As String, ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Integer, ByVal y As Integer)
  126.     If IntroComplete And Button = vbLeftButton Then
  127.         Merlin.Play "Surprised" 'Play Merlins's Suprised
  128.                                 'animation
  129.         Merlin.Speak "Be careful with that pointer!|Don't touch me!|OUCH!|Don't try to fondle me!|Get back to your programming!"
  130.             'make Merlin speak the text, this can also be from a textbox etc.
  131.             'the '|' character is an OR, so the Agent chooses which text to say randomly, v cool
  132.         Merlin.Play "RestPose"
  133.             'Return to Merlin's Rest Pose
  134.     End If
  135. End Sub
  136.  
  137. Private Sub Agent_Command(ByVal UserInput As Object)
  138.     Select Case UserInput.Name
  139.         Case "ChPoofs" 'If they said the command with the Key 'ChPoofs' then...
  140.             If Agent.AudioOutput.Enabled Then   'If they have AudioOutput installed..
  141.                 Merlin.Speak "Yeah I want cheesy poofs!", "ChPoofs.lwv"
  142.                 'Say "Yeah I want Cheesy Poofs", and play
  143.                 'the ChPoofs Linguistically Enhanced Wave
  144.                 'Sound file at the same time,
  145.                 'they are basically Wave files with the words
  146.                 'and punctuation written into them
  147.                 'Download the program for it from
  148.                 'http://msdn.microsoft.com/workshop/imedia/agent/default.asp
  149.                 'or wherever it is now, but DON'T ASK ME!
  150.                 'I am NOT going to e-mail a 6mb file to you :)
  151.             Else
  152.                 Merlin.Speak "You do not have the Lernout & Houspie TrueVoice engine installed!  Please download and install it from http://msdn.microsoft.com/workshop/imedia/agent/default.asp"
  153.             End If
  154.         Case "Internet"
  155.             If Agent.AudioOutput.Enabled Then
  156.                 Merlin.Speak ".", "KingOfTheHill.wav"
  157.                     'They can also speak wav files, the
  158.                     '[TEXT] and [URL] can be omitted
  159.                     '(left out), so you can have just text,
  160.                     'just a sound file, or both
  161.                     '(or neither, though that would be useless!)
  162.                 'An hour ago this worked fine without the ".",
  163.                 'though it wont now... try removing it :)
  164.             Else
  165.                 Merlin.Speak "You do not have the Lernout & Houspie TrueVoice engine installed!  Please download and install it from http://msdn.microsoft.com/workshop/imedia/agent/default.asp"
  166.             End If
  167.         Case "OffChar"
  168.             Merlin.Speak "Yes, \pau=200\you can use Office Assistant ACS character files, though they do not have the same animations as proper characters do, and they often cannot speak, only mime.. \pau=700\So I guess you will never hear Clippit's voice.."
  169.                 '\pau=200\ is a 'speech modifier'
  170.                 'see at the end for a defini